<template>
    <div>
        <h1>Test</h1>
    </div>
</template>
    
<script setup lang="ts">
import service from '@/utils/request'
import { clippingParents } from '@popperjs/core';
import { nextTick, onMounted, onUpdated, ref, watch } from 'vue'
//x轴
const xAxle = ref([])
// y轴数据
const temAxle = ref([])
const humAxle = ref([])

const brightnessStatusAxle = ref([])
const deviceData = () => {
    console.log("挂在请求");

    service.post('/deviceStatus/queryOneDay', {}).then(res => {
        //收拢

        humAxle.value = res.data.map((res: { deviceTemperature: number }) => res.deviceTemperature)
        console.log(humAxle.value, '當前数据集')
        //获取温度湿度光感平均值
        console.log("打印光感的平均值");
        console.log("打印光感数组");
        console.log(brightnessStatusAxle.value);



        // params.value?.push(calculateAverage(brightnessStatusAxle.value))
        // params.value?.push(calculateAverage(humAxle.value))
        // params.value?.push(calculateAverage(humAxle.value)

        //x轴收拢
        xAxle.value = res.data.map((res: { deviceIntoTime: any }) => formatTime(res.deviceIntoTime))
    })
    //时间格式化
    function formatTime(dateString: any) {
        const date = new Date(dateString)
        const year = date.getFullYear()
        const day = date.getDate() // 获取日期中的日
        const hour = date.getHours() // 获取小时
        const minute = date.getMinutes() // 获取分钟
        // 根据需要的格式拼接时间字符串
        const formattedTime = `${year}${day} ${hour}:${minute}`
        return formattedTime
    }   
}
onMounted(() => {
        deviceData()
    })
</script>
    
<style></style>
    